package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-29
 * Time: 19:46
 */
public class PalindromicDateCounter {

    public static void main(String[] args) {
        int count = 0;
        for (int year = 1; year <= 9999; year++) {
            String yearStr = String.format("%04d", year); // 确保年份是4位数
            for (int month = 1; month <= 12; month++) {
                String monthStr = String.format("%02d", month); // 月份补零
                // 检查年份的后两位是否与月份相同
                if (yearStr.substring(2).startsWith(monthStr)) {
                    int dayMax = getDaysInMonth(year, month); // 获取该月的天数
                    for (int day = 1; day <= dayMax; day++) {
                        String dayStr = String.format("%02d", day); // 日期补零
                        String dateStr = yearStr + monthStr + dayStr; // 完整日期
                        // 检查日期是否是回文
                        if (dateStr.equals(new StringBuilder(dateStr).reverse().toString())) {
                            count++;
                        }
                    }
                }
            }
        }
        System.out.println("结果为： " + count);
    }

    // 辅助方法：获取指定年份和月份的天数
    private static int getDaysInMonth(int year, int month) {
        switch (month) {
            case 1: case 3: case 5: case 7: case 8: case 10: case 12:
                return 31;
            case 4: case 6: case 9: case 11:
                return 30;
            case 2:
                // 判断是否为闰年
                return isLeapYear(year) ? 29 : 28;
            default:
                throw new IllegalArgumentException("Invalid month: " + month);
        }
    }

    // 辅助方法：判断是否为闰年
    private static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
}


class Player {
    public int Level;
    public int Exp;

    public Player() {
        this.Level = 1;
        this.Exp = 0;
    }

    public void addExp(int exp) {
        int totalExp = this.Exp+exp;
        int nowLevel = this.Level;
        int maxExp = getMaxExp(this.Level);

       if(totalExp > maxExp) {
           totalExp -= maxExp;
           nowLevel++;
       }
       this.Level = nowLevel;
       this.Exp = totalExp;
    }
//    当前等级最大经验即从level升级到level+1所需经验值
    int getMaxExp(int level) {
        return level*10;
    }
}